<?php include $this->getViewFile('/common/Head'); ?>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
   <?php include $this->getViewFile('/common/Nav') ?>
   <form class="J_ajaxForm"  method="post" id="myform">
   <div class="h_a">基本属性</div>
   <div class="table_full">
   <table width="100%" class="table_form contentWrap">
        <tbody>
          <tr >
            <th width="100">商品地址</th>
            <td><input type="text" name="url" value="<?php echo $data->url?>" class="input length_6" id="url" placeholder="http://">
              <span id="get_good" class="J_ajax_getiteminfo btn">获取最新信息</span>
            </td>
          </tr>

          <tr>
            <th>商品标题</th>
            <td><input type="text" name="title" value="<?php echo $data->title?>" class="input length_6" id="title" placeholder="商品标题"></td>
          </tr>




          <tr>
            <th>缩略图</th>
            <td><input type="text" name="thumb" value="<?php echo $data->thumb?>" class="input length_6" id="thumb" placeholder="http://"></td>
          </tr>

         <tr>
          <th></td>
          <td>
          <div class="thumb">
          </div></td>
         </tr>

          <tr>
            <th>商品价值</th>
            <td><input type="text" name="worth" class="input length_1" value="<?php echo $data->worth?>" id="worth"></td>
          </tr>

          <tr>
            <th>兑换积分</th>
            <td><input type="text" name="integral" class="input length_1" value="<?php echo $data->integral?>" id="integral"></td>
          </tr>

          <tr>
            <th>兑换总数</th>
            <td><input type="text" name="quantum" class="input length_1" value="<?php echo $data->quantum?>" id="quantum"></td>
          </tr>
          <tr>
            <th>兑换次数</th>
            <td><input type="text" name="frequency" class="input length_1" value="<?php echo $data->frequency?>" id="frequency"> <span>每人同个商品允许兑换几次，0不限</span></td>
          </tr>

          <tr>
          <th>兑换开始展示时间</th>
          <td><input type="text" name="start_time" class="input length_2 J_datetime " value="<?php echo  empty($data->start_time) ? '' : date('Y-m-d 10:00',$data->start_time)?>" placeholder="上架时间"></td>
         </tr>

          <tr>
          <th>兑换开始时间</th>
          <td><input type="text" name="exchange_start_time" class="input length_2 J_datetime " value="<?php echo  empty($data->exchange_start_time) ? '' : date('Y-m-d H:i:s',$data->exchange_start_time)?>" placeholder="兑换开始时间"></td>
         </tr>

         <tr>
            <th>允许兑换会员组</th>
            <td><?php echo Form::checkbox(MembersGroupModel::model()->getGroupArr(),$data->member_group,'name="member_group[]"'); ?></td>
          </tr>
          <tr>
            <th>状态</th>
            <td>

              <?php echo Form::radio(RedeemModel::getStatusHtmlList(),$data->status,'name="status"'); ?>
            </td>
          </tr>

          <tr>
            <th>付款状态</th>
            <td>

              <?php echo Form::radio(RedeemModel::getPayStatusHtmlList(),$data->pay_status,'name="pay_status"'); ?>
            </td>
          </tr>


          <tr>
            <th>排序</th>
            <td><input type="text" name="listorder" class="input length_1" value="<?php echo $data->listorder?>" id="listorder"></td>
          </tr>
          


          <tr>
            <th>商家ID</th>
            <td><input type="text" name="uid" class="input length_1" value="<?php echo $data->uid?>" id="uid"></td>
          </tr>

          <tr>
            <th>淘宝商品ID</th>
            <td><input type="text" name="product_id" class="input length_1" value="<?php echo $data->product_id?>" id="product_id"></td>
          </tr>

          <tr height="50">
            <th>商品介绍</th>
            <td><textarea id="introduction" class="length_6" name="introduction"><?php echo $data->introduction; ?></textarea></td>
          </tr>

          <tr>
            <th>佣金百分比</th>
            <td><input type="text" name="commission" class="input length_1" value="<?php echo $data->commission?>" id="commission">填写数字类型</td>
          </tr>

          <tr>
            <th>默认时间间隔</th>
            <td><input type="text" name="scoregood_intervals" class="input length_1" value="<?php echo $data->scoregood_intervals?>" id="scoregood_intervals"></td>
          </tr>


        </tbody>
      </table>
   </div>
   <div class="btn_wrap">
      <div class="btn_wrap_pd">
    <input type="hidden" name="id" value="<?php echo $data->id?>" />
        <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">确认</button>
      </div>
    </div>
    </form>
</div>
<script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
<script>
function getInfo() {
    var product_id = $('input[name="url"]').val();
    if (product_id == '') {
        return false;
    }
    var but = $("#get_good");
    var text = $(but).text();    
    $(but).text('获取中...');

    $.getJSON('<?php echo YzwController::U('goodsbm/public_iteminfo') ?>', {product_id: product_id}, function(data) {
            $(but).text(text);
            if (data.status) {
                //$('#RedeemModel_url').val(data.url);
                $('#title').val(data.title);
                $('#product_id').val(data.product_id);
                $('#worth').val(data.p_price);

                var imgstr = '';
                if (data.images) {
                    $.each(data.images, function(i, v) {
                        if (i == 0) {
                            $('#thumb').val(v);
                            imgstr += '<img class="current" width="160" height="160" src=' + v + ' />';
                        } else {
                            imgstr += '<img  width="160" height="160"  src=' + v + ' />';
                        }
                    });
                    $('div.thumb').html(imgstr);
                }
            } else {
                if (data.info) {
                    $('input[name="url"]').val('');
                    alert(data.info);
                }
            }
        });
}

$("#get_good").click(function(){
  getInfo();
})

$(document).on('click', 'div.thumb img', function(){
    $('div.thumb img').removeClass('current');
    $(this).addClass('current');
    $('#thumb').val(this.src);      
})


</script>
</body>
</html>